import React, {PropsWithChildren, useState} from "react"
import styles from "./FloatButton.module.sass"
import {Button, ButtonProps,} from "@nutui/nutui-react-taro";

export interface FloatButtonProps {
    icon: ButtonProps['icon']
    onClick?: ()=>Promise<void>
}

const FloatButton: React.FC<PropsWithChildren<FloatButtonProps>> = (props) => {
    const [loading,setLoading] = useState(false)
    return <>
        <Button type={"primary"} loading={loading} className={styles.button} icon={props.icon} onClick={async ()=> {
            if (props.onClick) {
                setLoading(true)
                try {
                    await props.onClick()
                } finally {
                    setLoading(false)
                }
            }
        }}/>
    </>
}

export default FloatButton